<?php

	namespace Phptricks\system\library\date_time;

	/**
	 * Description of models
	 *
	 * @author Sammy Guergachi <sguergachi at gmail.com>
	 */
	use Phptricks\system\core\library\library;
	use Phptricks\system\library\PhptricksExceptions\PhptricksExceptions as Exc;

	class date_time implements library{

		public $_current_time = '00:00:00';
		public $_current_date = '0000-00-00';
		public $_full_date = '0000-00-00 00:00:00';
		public $_date = array();
		private static $_instance = null;

		public static function &getinstance(){
			if (self::$_instance === null) {
				self::$_instance = new \Phptricks\system\library\date_time\date_time();
			}
			return self::$_instance;
		}

		public function __construct(){
			$this->_full_date = date("Y-m-d H:i:s");
			$this->_date = array(
				'full_date' => date("Y-m-d H:i:s"),
				'date' => date("Y-m-d"),
				'time' => date("H:i:s"),
				'y' => date("Y"),
				'm' => date("m"),
				'd' => date("d"),
				'h' => date("H"),
				'i' => date("i"),
				's' => date("s")
			);
		}

		public function get_time_difference($start_date = null, $end_date = null){
			if (empty($start_date) || empty($end_date)) {
				return false;
			}
			$start_date = \date_create($start_date);
			$end_date = \date_create($end_date);
			$array_diff = (array) \date_diff($start_date, $end_date);
			return $array_diff;
		}

		public function get_date($format = 'Y-m-d'){
			return date($format);
		}

		public function add_date($type = '', $num = '+1', $format = 'Y-m-d'){
			$array_type = array(
				'y' => 'year',
				'm' => 'month',
				'w' => 'week',
				'd' => 'days',
				'h' => 'hours',
				'ms' => 'minutes',
				's' => 'seconds'
			);

			$date = date($format, strtotime("$num $array_type[$type]"));
			return $date;
		}

	}

?>
